// index.js
// 获取应用实例
const App = getApp()
const api = require('../../utils/requst.js').API;
Page({
  data: {
    top:0,
    nextMargin: 0,
    current_scroll: '1',
    pageSize:10,
    pageNum: 1,
    list: [],
    loadState:1
  },
  getData(){
    console.log(this.data.pageSize)
    api.workList({pageSize:this.data.pageSize,pageNum: this.data.pageNum,workTypeId:this.data.current_scroll}).then(res=>{
      var list = res.data.data.records
      if(list.length<this.data.pageSize){
        this.setData({
          loadState:3
        })
      }else{
        this.setData({
          pageNum:this.data.pageNum+1,
          loadState:1
        })
      }
      this.setData({list:this.data.list.concat(list)})
  })
  },
  onLoad(para) {
    console.log(para.workTypeId)
    let top =60+App.globalData.systemInfo.statusBarHeight + App.globalData.menuButton.height + (App.globalData.menuButton.top - App.globalData.systemInfo.statusBarHeight)*2
    console.log(top)
    this.setData({top:top,current_scroll:para.workTypeId})
    this.getData()
  },
  handleChangeScroll ({ detail }) {
    this.setData({
      pageNum: 1,
      list: [],
      loadState:1,
        current_scroll: detail.key
    });
    this.getData()
  },
  toDetail(e){
    let index = e.currentTarget.dataset['index'];
    wx.navigateTo({
      url: '../workDetail/index?id='+this.data.list[index].id,
    })
  },
  //触底响应函数
  onReachBottom() {
    console.log(4444)
    if(this.data.loadState==1){
      this.getData()
    }
 }
})
